/**
 * 产品修改js
 */
var comValidform = null;
var productInfoSetSaleTime = {
	returnStatus:false,
	dataCache : null,
	key:null,
	startEvent : function() {
		productInfoSetSaleTime.showInfo();
		comValidform = $(".com-addForm").Validform({
			tiptype : 2,
			tipSweep : true,
			beforeSubmit : function(curform) {
				var url = 'mgr/ProductInfoCtrl/setSaleTime';
				var id = $('input[name="id"]').val();
				var startSaleTime = $('input[name="startSaleTime"]').val();
				var endSaleTime = $('input[name="endSaleTime"]').val();
				var saleOutTime = $('input[name="saleOutTime"]').val();
				var chgBuyTypeTime = $('input[name="chgBuyTypeTime"]').val();
				var params ={
			   		'id':id,
				    'startSaleTime': startSaleTime,
				    'endSaleTime':endSaleTime,
					'saleOutTime':saleOutTime,
					'chgBuyTypeTime':chgBuyTypeTime
				};
				var cb = function(data) {
					alert(data.msg);
					// 成功返回
					if (data.resultCode == 200) {
						localStorage.removeItem(productInfoSetSaleTime.key);
						
						var singleObj = data.result;
						localStorage.setItem(singleObj.id
								+ "_ProductType02_Key", JSON
								.stringify(singleObj));
                        productInfoSetSaleTime.returnStatus = true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},

	showInfo: function() {
	 
		var id = art.dialog.data('updId');
		productInfoSetSaleTime.key = id + "_ProductType02_Key";

		$("input[name='id']").val(id);
		var ret = eval('(' + localStorage.getItem(productInfoSetSaleTime.key) + ')');

		if(ret.startSaleTime != null && ret.startSaleTime!=''){
			var startSaleTime=(new Date(ret.startSaleTime)).format('yyyy-MM-dd hh:mm:00');
			$("input[name='startSaleTime']").val(startSaleTime);
		}

		if(ret.endSaleTime != null && ret.endSaleTime!=''){
			var endSaleTime=(new Date(ret.endSaleTime)).format('yyyy-MM-dd hh:mm:00');
			$("input[name='endSaleTime']").val(endSaleTime);
		}

		if(ret.saleOutTime != null && ret.saleOutTime!=''){
			var saleOutTime=(new Date(ret.saleOutTime)).format('yyyy-MM-dd hh:mm:00');
			$("input[name='saleOutTime']").val(saleOutTime);
		}


		if(ret.chgBuyTypeTime != null && ret.chgBuyTypeTime!=''){
			var chgBuyTypeTime=(new Date(ret.chgBuyTypeTime)).format('yyyy-MM-dd hh:mm:00');
			$("input[name='chgBuyTypeTime']").val(chgBuyTypeTime);
		}

	},
	init : function() {
		productInfoSetSaleTime.startEvent();
	}
}
$(document).ready(function() {
	productInfoSetSaleTime.init();
});
function submitForm() {
	comValidform.submitForm();
	return   productInfoSetSaleTime.returnStatus;
}